from django.shortcuts import render
from django.http import HttpResponse,HttpResponseRedirect
from .models import *
from .verify import *

@verify_control
def api_asset_add(request):
    """
        @author:donghaiming
        @date:2018/10/11
        提交方式：POST
        数据格式：{"add_asset_name":"xxx"}
    """
    
    try:
        info = request.POST["add_asset_name"].strip()
    except KeyError:
        return HttpResponse('提交信息为空')
    else:
        if info != "":
            try:
                Asset.objects.create(asset_name=info)
            except django.db.utils.IntegrityError:
                return HttpResponse('资产名（{}）已经存在'.format(info))
        else:
            return HttpResponse("添加的资产名不能为空")
    
















#资产管理系统
def asset_manage(request):
        context = {'message':'欢迎来到本系统'}
        return render(request,'asset/asset_manage.html',context)

#资产添加
def function(request):

    return render(request,'asset/资产.html')

#资产添加运算
def asset(request):
	
    info = dict(request.POST)
    print(info)
    '''
                info = {'asset_name': ['×××'], 'asset_num': ['××']}
    '''
        

    return HttpResponse('ok')

#资产删除
def asset_del(request):
        context = {}
        return render(request,'asset/asset_del.html',context)

#资产删除运算
def asset_del_db(request):
        info = dict(request.POST)
        print(info)
        
        return HttpResponse('ok')

#资产查询
def asset_find(request):
        context = {}
        return render(request,'asset/asset_find.html',context)

#资产查询运算
def asset_find_db(request):
        info = dict(request.POST)
        print(info)
        return HttpResponse('ok')

#资产修改
def asset_alter(request):
        context = {}
        return render(request,'asset/asset_alter.html',context)

#资产修改运算
def asset_alter_db(request):
        info = dict(request.POST)
        print(info)
        return HttpResponse('ok')
